import { createHighlighter, type Highlighter } from 'shiki'

let highlighter: Highlighter | null = null

export async function initHighlighter() {
  highlighter = await createHighlighter({
    themes: ['github-dark', 'github-light'],
    langs: ['vue', 'javascript', 'html']
  })
  return highlighter
}

export function highlight(code: string, lang: string) {
  if (!highlighter) throw new Error('Shiki highlighter not initialized!')
  return highlighter.codeToHtml(code, {
    lang,
    themes: {
      light: 'github-light',
      dark: 'github-dark'
    },
    defaultColor: false
  })
}
